<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
	<meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<title>乐鲜生活-注册</title>
	<link rel="shortcut icon" href="favicon.ico" />
	<link rel="bookmark" href="favicon.ico" />
	<link rel="stylesheet" type="text/css" href="css/register.css" />
	<link rel="stylesheet" type="text/css" href="css/base.css" />
	<link rel="stylesheet" type="text/css" href="css/base1.css" />
	<link rel="stylesheet" type="text/css" href="css/asyncbox/asyncbox.css" />
</head>
<body>
	<div id="wrapper">
		<div id="header"></div>
		
		<div class="main">
			<!--主体内容部分-->
			<div class="search search_marg">
				<!--搜索区域-->
				<div class="float_left reg_log">
					<!--商店图标-->
					<a href="index.html"><img src="icons/logo.png" alt="log"></a>
				</div>
				<div class="float_left reg_h3 z-margin2" style="margin-top: 36px">
					<h3 style="font-size: 16px; color: #ff4200">注册</h3>
				</div>
				<div class="clr"></div>
			</div>
			<div class="header" style="padding-top: 30px">
				<!--头部开始部分-->
				<ul class="ua">
					<li class="li1 li1-a">填写账户信息</li>
					<li class="li4 li4-b zb2">注册成功</li>
				</ul>
			</div>
			<!--头部结束部分-->
			<div class="contentstart">
				<!--内容部分-->
				<div class="registerForm">
					<div>
						<span class="text"> <span class="required"></span>手机号码：
						</span> <input type="text" class="span3" id="phone" placeholder="请输入手机号码" />
					</div>
					<div>
						<span class="text"> <span class="required"></span>真实姓名：
						</span> <input type="text" value="" id="username" placeholder="请输入真实姓名" />
					</div>
					<div>
						<span class="text"> <span class="required"></span>请设置密码：
						</span> <input type="password" value="" id="password" placeholder="请输入密码" />
					</div>
					<div>
						<span class="text"> <span class="required"></span>请确认密码：
						</span> <input type="password" value="" id="surepassword" placeholder="请确认密码" />
					</div>
					<!-- 暂不处理短信验证码 -->
					<!-- 
					<div>
						<span class="text">
							<span class="required"></span>短信验证码：
						</span>
						<input type="text" value="" placeholder="请输入验证码" id="validateCode" />
						<input id="validate" class="validateCode"
							style="border: 1px solid #999; padding: 0 2px; background: #f2f2f2; width: 74px; height: 30px; font-size: 12px; text-align: center; color: #666; cursor: pointer"
							value="获取验证码" />
					</div>
					-->
					<div>
						<span class="text">&nbsp;</span>
						<a href='javascript:void(0);' class="submit" id="submit">立即注册</a>
						<div style="margin-top: 10px; text-indent: 125px">
							注册即视为同意《 <a style="font-size: 15px; color: #ff4200;"
								href="disclaimer.html">乐鲜生活平台服务协议</a>》
						</div>
					</div>
				</div>
			</div>
		</div>
		
		<div class="footer" id="footer"></div>
	</div>
	<script type="text/javascript" src="js/site/jquery-1.8.2.min.js"></script>
	<script type="text/javascript" src="js/site/AsyncBox.v1.4.js"></script>
	<script type="text/javascript" src="js/site/validate.js"></script>
	<script type="text/javascript" src="js/site/common.js"></script>
	<script type="text/javascript">
		$(function() {
			$("#validate").click(
				function() {
					var validate = $(this);
					var count = 60;
					var phone = $.trim($("#phone").val());
					if (!validateUtil.validateEmpty(phone)) {
						asyncbox.tips("手机号码不能为空，请输入手机号码!", asyncbox.Level.error);
						return;
					}
					if (!validateUtil.validatePhone(phone)) {
						asyncbox.tips("请输入正确的手机号码!", asyncbox.Level.error);
						return;
					}

					var param = {
						"phone" : phone,
						"type" : 1,
						"platform" : 2
					};

					$.postAjax("/validation/getValidateCode.do", param,
						function(json) {
							if (json.code) {
								asyncbox.tips(json.message, asyncbox.Level.error);
								return;
							}
							asyncbox.tips(json.message, asyncbox.Level.success);
							var obj = $("#validate");
							settime(obj);
						}
					);
				}
			);

			var countdown = 60;
			function settime(obj) {
				if (countdown == 0) {
					$(obj).attr("disabled", false);
					$(obj).attr("value", "发送验证码");
					$(obj).css("cursor", "");
					countdown = 60;
				} else {
					$(obj).attr("disabled", true);
					$(obj).css("cursor", "default");
					$(obj).attr("value", countdown + "s");
					countdown--;
					setTimeout(function() {
						settime(obj);
					}, 1000);
				}
			}

			$("#submit").click(
				function() {
					var phone = $.trim($("#phone").val());
					var username = $.trim($("#username").val());
					var password = $.trim($("#password").val());
					var surepassword = $.trim($("#surepassword").val());
					// 先注释验证码模块
					/* var validateCode = $.trim($("#validateCode").val()); */
					if (!validateUtil.validateEmpty(phone)) {
						asyncbox.tips("手机号码不能为空，请输入手机号码",
								asyncbox.Level.error);
						return;
					}
					if (!validateUtil.validatePhone(phone)) {
						asyncbox.tips("请输入正确的手机号码！",
								asyncbox.Level.error);
						return;
					}
					if (!validateUtil.validateEmpty(username)) {
						asyncbox.tips("真实姓名不能为空",
								asyncbox.Level.error);
						return;
					}
					if (!validateUtil.validateMaxLength(username,
							15)) {
						asyncbox.tips("真实姓名不能超过15位",
								asyncbox.Level.error);
						return;
					}
					if (!validateUtil.validateEmpty(password)) {
						asyncbox.tips("请输入密码！",
								asyncbox.Level.error);
						return;
					}
					if (!validateUtil
							.validateMinLength(password, 6)) {
						asyncbox.tips("请输入6到16位密码！",
								asyncbox.Level.error);
						return;
					}
					if (!validateUtil.validateMaxLength(password,
							16)) {
						asyncbox.tips("请输入6到16位密码！",
								asyncbox.Level.error);
						return;
					}

					if (!validateUtil.validateEmpty(surepassword)) {
						asyncbox.tips("请输入确认密码！",
								asyncbox.Level.error);
						return;
					}

					if (password != surepassword) {
						asyncbox.tips("两次密码不一致",
								asyncbox.Level.error);
						return;
					}

					var role = $("ul.select>li.selected:eq(0)")
							.attr("value");
					var data = {
						phone : phone,
						userName : username,
						passwd : password,
						/* validateCode : validateCode, */
						role : role
					};
					$.postAjax("/user/register.do", data,
						function(json) {
							if (json.code) {
								asyncbox.tips(json.message, asyncbox.Level.error);
								return;
							}
							var user = encodeURIComponent(username);
							window.location = 'registersuccess.html?username=' + user + "&phone=" + phone;
						},
						function() {
							asyncbox.tips("网络连接错误", asyncbox.Level.error);
						}
					);
				}
			);
		});
	</script>
</body>
</html>